<html>
<head>
<title>Appointment Scheduling System</title>
<script src="formValidation.js"></script>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body id='index'>
	<div id='body_container'>
	<div id='header'><div id='banner'>NITC Appoinmtent Scheduling System</div></div>
	
<?php
	include "dbconnect.php";
	error_reporting(0);
	session_start();
	if(isset($_SESSION['email']))
		header("location:home.php");
	$invalid = false;
	if(isset($_POST['login']))
	{
		$email = $_POST['email'];
		$pass = $_POST['password'];
		$usertype = $_POST['usertype'];
		$query="select password from ".$usertype." where email='$email'";
		$result=mysql_query($query);
		$resultArr=mysql_fetch_array($result);
		if($pass == $resultArr[0])
		{
			$_SESSION['email'] = $email;
			$_SESSION['usertype'] = $usertype;
			if($usertype == "faculty")
				mysql_query("UPDATE  faculty  SET onlineStat = '1' WHERE  email =  '$email'");
																				
			header('Location:home.php');
		}	
		else
			$invalid = true;
	}	
?>	
	
	<div id='page_container'>
	<div id="page">
	<div id='page_top'></div>
	<div id='forms'>
	<table border="0" cellpadding="10">
	<tr>
	<td>
	<div id="sign_up">
	<fieldset name="main" id='signup_fieldset'>
		<legend> Sign Up </legend>
		<form name="myForm" action="register.php" onSubmit="return validateForm()" method="post">
			<p>
			First name*: <input type="text" name="fname"><br>
			Last name: &nbsp;&nbsp;<input type="text" name="lname"><br>
			Email*: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="email"><br>
			Password*: &nbsp;&nbsp;<input type="password" name="password"><br>
			
			<input type="submit" value="Sign Up"><br>
			Note: * fields are mandatory.
			</p>
		</form>
	</fieldset>
	</div>
	</td>
	<td>
	<div id="login">
	<fieldset name="main" height="260" id='signin_fieldset'>
		<legend> Sign In </legend>
		<form name="myForm1" action="index.php" onSubmit="return validatesignin()" method="post" class='form'>
			<table>
			<tr><td>Email*:</td><td><input type="text" name="email"></td></tr>
			<tr><td>Password*:</td><td><input type="password" name="password"></td></tr>
			</table>
			Account-type*:<input name="usertype" type="radio" value="student">Student&nbsp;
			<input name="usertype" type="radio" value="faculty">Faculty
			<?php
			if($invalid)
				echo "<br /><span class='error'>Email Id Or Password Incorrect.</span>"; 
			?>
			<div id='login_button'><input type="submit" name="login" value="Login"></div>
			Note: * fields are mandatory.
		</form>
	</fieldset>
	</div>
	</td>
	</tr>
	</table>
	</div>
    <div id='page_bottom'></div>
	</div>
	</div>
	<?php include 'footer.php'; ?>
	</div>
</body>
</html>
